package com.thewell79.android;

import android.app.Application;

import com.android.volley.DefaultRetryPolicy;
import com.android.volley.Request;
import com.android.volley.RequestQueue;
import com.android.volley.toolbox.ImageLoader;
import com.android.volley.toolbox.Volley;
import com.thewell79.android.Request.BitmapLruCache;

public class VolleyApplication extends Application {

	public static VolleyApplication mInstance;
	private RequestQueue mQueue;
	private ImageLoader mImageLoader;

	public void onCreate() {
		mInstance = this;
	}

	public static synchronized VolleyApplication getmInstance() {
		return mInstance;
	}

	public RequestQueue getRequestQueue() {

		if (mQueue == null) {
			mQueue = Volley.newRequestQueue(this);
		}

		return mQueue;
	}

	public void RequestCommit(Request<?> request) {
		getRequestQueue().add(request);
	}

	public void RequestCommitTimeOut(int millisecond, Request<?> request) {
		request.setRetryPolicy(new DefaultRetryPolicy(millisecond,
				DefaultRetryPolicy.DEFAULT_MAX_RETRIES,
				DefaultRetryPolicy.DEFAULT_BACKOFF_MULT));
		getRequestQueue().add(request);
	}

	public ImageLoader getImageLoader() {

		if (mImageLoader == null) {
			mImageLoader = new ImageLoader(getRequestQueue(),
					new BitmapLruCache());
		}

		return mImageLoader;
	}
}
